package com.zyh.scs.admin.base.open;

import com.zyh.scs.admin.api.constant.open.CodeSet;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 员工-分页 response
 * @param <T>
 *
 * @author hwh
 */
@Data
@ToString
public class LaoSheAccountTotalResponse<T> implements Serializable{

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	protected Integer errCode;

	protected String errMsg;

	protected String traceId;

	protected T data;

	protected Long total = 0L;

	// biz-当前页账户余额
	protected BigDecimal totalBalance = BigDecimal.ZERO;

	public LaoSheAccountTotalResponse(){
		this.errCode = CodeSet.SYSTEM_EXCEPTION.getCode();
		this.errMsg = "处理失败";
		this.traceId = "";
		this.total = 0L;
		this.totalBalance = BigDecimal.ZERO;
	}

	public LaoSheAccountTotalResponse(Integer code, String msg, String traceId, Long total, BigDecimal userBalance){
		this.errCode = code;
		this.errMsg = msg;
		this.traceId = traceId;
		this.total = total;
		this.totalBalance = userBalance;
	}
	
	public static <T> LaoSheAccountTotalResponse<T> success(String msg, String traceId, Long total, BigDecimal userBalance){
		LaoSheAccountTotalResponse<T> result = new LaoSheAccountTotalResponse<>();
		result.setErrCode(CodeSet.SUCCESS.getCode());
		result.setErrMsg(msg);
		result.setTraceId(traceId);
		result.setTotal(total);
		result.setTotalBalance(userBalance);
		return result;
	}
	public static <T> LaoSheAccountTotalResponse<T> successData(T object, String traceId, Long total, BigDecimal userBalance){
		LaoSheAccountTotalResponse<T> result = new LaoSheAccountTotalResponse<>();
		result.setErrCode(CodeSet.SUCCESS.getCode());
		result.setData(object);
		result.setErrMsg("处理成功");
		result.setTraceId(traceId);
		result.setTotal(total);
		result.setTotalBalance(userBalance);
		return result;
	}

	public static <T> LaoSheAccountTotalResponse<T> error(CodeSet codeSet, String traceId, Long total, BigDecimal userBalance){
		LaoSheAccountTotalResponse<T> result = new LaoSheAccountTotalResponse<>();
		result.setErrCode(codeSet.getCode());
		result.setErrMsg(codeSet.getCodeName());
		result.setTraceId(traceId);
		result.setTotal(total);
		result.setTotalBalance(userBalance);
		return result;
	}

	public static <T> LaoSheAccountTotalResponse<T> error(Integer errCode,String errMsg, String traceId){
		LaoSheAccountTotalResponse<T> result = new LaoSheAccountTotalResponse<>();
		result.setErrCode(errCode);
		result.setErrMsg(errMsg);
		result.setTraceId(traceId);
		return result;
	}

	public static <T> LaoSheAccountTotalResponse<T> error(Integer errCode, String errMsg, String traceId, Long total, BigDecimal userBalance){
		LaoSheAccountTotalResponse<T> result = new LaoSheAccountTotalResponse<>();
		result.setErrCode(errCode);
		result.setErrMsg(errMsg);
		result.setTraceId(traceId);
		result.setTotal(total);
		result.setTotalBalance(userBalance);
		return result;
	}

	public static <T> LaoSheAccountTotalResponse<T> error() {
		LaoSheAccountTotalResponse<T> result = new LaoSheAccountTotalResponse<>();
		result.setErrCode(CodeSet.SYSTEM_EXCEPTION.getCode());
		result.setErrMsg("系统处理失败");
		result.setTraceId("");
		result.setTotal(0L);
		result.setTotalBalance(BigDecimal.ZERO);
		return result;
	}

	public void setCodeSet(CodeSet codeSet) {
		this.setErrCode(codeSet.getCode());
		this.setErrMsg(codeSet.getCodeName());
		this.setTraceId("");
	}

	public void setCodeSet(CodeSet codeSet, Long total) {
		this.setErrCode(codeSet.getCode());
		this.setErrMsg(codeSet.getCodeName());
		this.setTraceId("");
		this.setTotal(total);
	}

}